home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_05 / 8n05064a < prev    next >
Text File  |  1990-04-17  |  1KB  |  41 lines

  1. Listing 3
  2.  
  3. /* header file to:
  4.       aid in conversion of FORTRAN code to C
  5.       perform a few useful functions in-line
  6. from Handbook of C Tools for Scientists and Engineers
  7.       by L. Baker
  8.  
  9. DEPENDENCIES: NONE
  10.  
  11. */ 
  12.  
  13.  
  14. /* in-line functions for use with 2D arrays: */
  15.  
  16. /* row major order as in C indices run 0..n-1 as in C*/
  17. #define INDEX(i,j)  [j+(i)*coln]
  18.  
  19. /*various loop constructors */
  20. #define DOFOR(i,to) for(i=0;i<to;i++)
  21. #define DFOR(i,from,to) for(i=from-1;i<to;i++)
  22. #define DOBY(i,from,to,by) for(i=from-1;i<to;i+=by)
  23. #define DOBYY(i,from,to,by) for(i=from;i<to;i+=by)
  24. #define DOBYYY(i,from,to) for(i=from;i<to;i++)
  25. #define DOV(i,to,by) for(i=0;i<to;i+=by)
  26. /* row major order as in C  indices run 1..n */
  27. /*#define INDEX1(i,j)  [j-1+(i-1)*n]
  28. */
  29. /* column major order, as in fortran: */
  30. #define INDEXC(i,j) [i-1+(j-1)*rown]
  31.  
  32. /* usage: if a(20,30) is matrix, then
  33. a(i,j) in C will be a INDEX(i,j) if n=30. */
  34.  
  35. /* to index vectors starting with 1 */
  36. #define VECTOR(i) [i-1]
  37.  
  38. #define min(a,b) (((a)<(b))? (a): (b))
  39. #define max(a,b) (((a)<(b))? (b): (a))
  40. #define abs(x)  ( ((x)>0.)?(x):-(x))
  41.